<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>商品采购统计</title>
<link rel="stylesheet" type="text/css" href="/static/jquery-easyui-1.3.3/themes/default/easyui.css"></link>
<link rel="stylesheet" type="text/css" href="/static/jquery-easyui-1.3.3/themes/icon.css"></link>
<script type="text/javascript" src="/static/jquery-easyui-1.3.3/jquery.min.js"></script>
<script type="text/javascript" src="/static/jquery-easyui-1.3.3/jquery.easyui.min.js"></script>
<script type="text/javascript" src="/static/jquery-easyui-1.3.3/locale/easyui-lang-zh_CN.js"></script>

<script type="text/javascript" src="/static/js/date.js"></script>
<script type="text/javascript">



	function formatAmountPayable(val,row){
		return "￥"+val;
	}
	
	
	$(document).ready(function(){

		$("#s_begin").datebox("setValue",genLastMonthDayStr()); // 设置上个月日期
		$("#s_end").datebox("setValue",genTodayStr()); // 设置当前日期
		
		
	});
	

	
	function formatPrice(val,row){
		return "￥"+val;
	}
	
	
	function search(){
		$('#dg').datagrid('loadData', { total: 0, rows: [] });  
		var s_begin=$("#s_begin").datebox("getValue");
		var s_end=$("#s_end").datebox("getValue");
		var typeId=$("#typeId").val();
		var codeOrName=$("#codeOrName").val();
		$.post("/admin/purchaseList/listCount",{bPurchaseDate:s_begin,ePurchaseDate:s_end,"type.id":typeId,codeOrName:codeOrName},function(result){
			var rows=result.rows;
			for(var i=0;i<rows.length;i++){
				var row=rows[i];
				var goodsRows=row.purchaseListGoodsList;
				for(var j=0;j<goodsRows.length;j++){
					var goodsRow=goodsRows[j];
					$('#dg').datagrid('appendRow',{
						number:row.purchaseNumber,
						type:"进货",
						date:row.purchaseDate,
						supplierName:row.supplier.name,
						code:goodsRow.code,
						name:goodsRow.name,
						model:goodsRow.model,
						typeName:goodsRow.type.name,
						unit:goodsRow.unit,
						price:goodsRow.price,
						num:goodsRow.num,
						amount:goodsRow.price*goodsRow.num
					});		
				}
			}
		},"json");	
		
		
		$.post("/admin/returnList/listCount",{bReturnDate:s_begin,eReturnDate:s_end,"type.id":typeId,codeOrName:codeOrName},function(result){
			var rows=result.rows;
			for(var i=0;i<rows.length;i++){
				var row=rows[i];
				var goodsRows=row.returnListGoodsList;
				for(var j=0;j<goodsRows.length;j++){
					var goodsRow=goodsRows[j];
					$('#dg').datagrid('appendRow',{
						number:row.returnNumber,
						type:"退货",
						date:row.returnDate,
						supplierName:row.supplier.name,
						code:goodsRow.code,
						name:goodsRow.name,
						model:goodsRow.model,
						typeName:goodsRow.type.name,
						unit:goodsRow.unit,
						price:goodsRow.price,
						num:goodsRow.num,
						amount:goodsRow.price*goodsRow.num
					});		
				}
			}
		},"json");	
	}
	

	function chooseGoodsType(){
		$("#dlg2").dialog("open").dialog("setTitle","选择商品类别");
		$("#typeTree").tree({
			url:'/admin/goodsType/loadTreeInfo',
			onLoadSuccess:function(node, data){
				var rootNode = $("#typeTree").tree('getRoot'); 
				$("#typeTree").tree('expand',rootNode.target);
			}
		});
	}
	
	function saveGoodsTypeChoose(){
		var node = $('#typeTree').tree('getSelected'); // 获取选中节点
		$("#typeId").val(node.id);
		$("#typeName").val(node.text);
		$("#dlg2").dialog("close");
	}
	
	function closeGoodsTypeChooseDialog(){
		$("#dlg2").dialog("close");
	}
	
</script>
</head>
<body  style="margin: 1px">

	<table id="dg" title="商品采购统计" class="easyui-datagrid" fit=true
	   fitColumns="true"  rownumbers="true" singleSelect="true"
	    toolbar="#tb" >
	   <thead>
	   	<tr>    
	   		<th field="number" width="50" align="center">单号</th>
	   	    <th field="type" width="20" align="center">类型</th>
	   		<th field="date" width="30" align="center">日期</th>
	   		<th field="supplierName" width="70" align="center" >供应商</th>
	   		<th field="code" width="20" align="center" >商品编号</th>
	   		<th field="name" width="50" align="center" >商品名称</th>
	   		<th field="model" width="30" align="center" >商品型号</th>
	   		<th field="typeName" width="30" align="center" >商品类别</th>
	   		<th field="unit" width="10" align="center" >单位</th>
	   		<th field="price" width="20" align="right" formatter="formatPrice">单价</th>
	   		<th field="num" width="20" align="center" >数量</th>
	   		<th field="amount" width="15" align="right" formatter="formatAmountPayable">总金额</th>
	   	</tr>
	   </thead>
	 </table>
	 
	 <div id="tb">
	 	<div style="padding-bottom: 5px">
	 		<fieldset style="border-color: #E7F0FF">
	 			<legend>统计设置</legend>
	 		&nbsp;&nbsp;&nbsp;往来日期：&nbsp;
	 		<input id="s_begin" class="easyui-datebox" editable=false  style="width:100px">
	 	&nbsp;&nbsp;-&nbsp;&nbsp;
	 		<input id="s_end" class="easyui-datebox" editable=false  style="width:100px">
		 		&nbsp;商品类别&nbsp;
	 		<input type="hidden" id="typeId"/>
	 		<input type="text" id="typeName"  style="width: 90px;" readonly="readonly" onclick="chooseGoodsType()"/>
	 		&nbsp;商品编码或者名称：&nbsp;<input type="text" id="codeOrName" size="20" onkeydown="if(event.keyCode==13) search()"/>
	 		&nbsp;&nbsp;<a href="javascript:search()" class="easyui-linkbutton" iconCls="icon-search" plain="true">搜索</a>
	 		</fieldset>
	 	</div>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  
	 </div>



 <div id="dlg2" class="easyui-dialog" style="width:180px;height:300px;padding: 10px 10px;top: 52px;left: 80px"
   closed="true" buttons="#dlg-buttons2">
   
   	<ul id="typeTree" class="easyui-tree"></ul>
   
  </div>
 
 <div id="dlg-buttons2">
 	<a href="javascript:saveGoodsTypeChoose()" class="easyui-linkbutton" iconCls="icon-ok" plain="true">选择</a>
 	<a href="javascript:closeGoodsTypeChooseDialog()" class="easyui-linkbutton" iconCls="icon-cancel" plain="true">关闭</a>
 </div>

</body>
</html>